#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#include "color.h"
#include "guess.h"
#include "click.h"
#include "leaderboard.h"
#include "configuration.h"
#include "homepage.h"

void show_main_menu(void)
{
	printf(L_RED);
	printf(BLINK "\t==== Welcome to GAME BOX !! ====""\n" NONE);

	printf(WHITE);
	printf("\n\t"
    	"=========== GAME BOX ===========\n\t"
		"================================\n\t"
		"*                              *\n\t"
    	"*       1. CLICK GAME          *\n\t"
		"*                              *\n\t"
    	"*       2. GUESS GAME          *\n\t"
		"*                              *\n\t"
    	"*       3. LEADERBOARD         *\n\t"
		"*                              *\n\t"
   		"*       4.    QUIT             *\n\t"
		"*                              *\n\t"
       	"================================\n\t"
		"*                              *\n\t"
    	"*       PLEASE SELECT 1~4:     *\n\t"
		"*                              *\n\t"
		"================================\n");
    printf(NONE);
}

/**
 * @brief   主菜单输入判断, 按下1选择疯狂点击游戏,
 *          按下2选择猜数字游戏, 按下3查看排行榜信息, 
 * 			按下4退出游戏盒子(按下4后接y退出, 其他返回)).
 * @param   void
 * @return  void
 */
void choice_main_menu(void)
{
	char input_main_menu[32];
	
	while (1) {
		set_buffered_input(false);
		input_main_menu[0] = getchar();
		set_buffered_input(true);

		switch (input_main_menu[0]) {
			case CLICK:
				system("clear");
				show_click_menu();
				choice_click_menu();
				break;

			case GUESS:
				system("clear");
				show_guess_menu();
				choice_guess_menu();
				break;

			case LEADERBOARD:
				system("clear");
				main_board();
				break;

            case QUIT_MAIN:
				system("clear");
            	show_main_menu();
				printf(L_RED "\n\tWhether to QUIT(y/n):" NONE);
                set_buffered_input(false);
				input_main_menu[0] = getchar();
                set_buffered_input(true);
				if (input_main_menu[0] == 'y') {
					system("clear");
					putchar('\n');
                	exit(EXIT_SUCCESS);
				} else {
					system("clear");
                	show_main_menu();
					choice_main_menu();
				}
				break;

			default :
				system("clear");
            	show_main_menu();
				printf(L_RED "\n\tERROR INPUT!\r\n" NONE);
				choice_main_menu();
				continue;
		}
	}
}


